
# coding: utf-8
# color table
# https://www.cnblogs.com/onemorepoint/p/7481643.html 

#柱状图
import numpy as np
import matplotlib.pyplot as plt

listemo = ['Anger', 'Disgust', 'Fear', 'Happiness', 'Neutral', 'Sadness', 'Surprise']
x = np.arange(7)   # 横坐标范围
D1 = [0.70, 0.50, 0.50, 0.92, 0.87, 0.84, 0.81]
D2 = [0.72, 0.48, 0.45, 0.94, 0.85, 0.86, 0.86]
D3 = [0.78, 0.50, 0.44, 0.94, 0.89, 0.83, 0.87]
D4 = [0.75, 0.53, 0.50, 0.95, 0.91, 0.85, 0.87]
plt.figure()
total_width, n = 0.8, 4   # 柱状图总宽度，有几组数据
width = total_width / 6   # 单个柱状图的宽度
x1 = x - width/0.68  # 第一组数据柱状图横坐标起始位置
x2 = x1 + width   # 第二组数据柱状图横坐标起始位置
x3 = x2 + width   # 第三组数据柱状图横坐标起始位置
x4 = x3 + width   # 第四组数据柱状图横坐标起始位置
plt.xlabel("Expression Category", fontdict={'size': 12})
plt.ylabel("Recognition Accuracy (%)", fontdict={'size': 12})
# plt.title("", fontdict={'size': 20})
plt.bar(x1, D1, width=width, label="Baseline",color='lightsalmon')
plt.bar(x2, D2, width=width, label="KFER",color='paleturquoise') 
plt.bar(x3, D3, width=width, label="IFER",color='moccasin')
plt.bar(x4, D4, width=width, label="Joint Learning",color='mediumpurple')
plt.xticks(x, listemo,fontsize=10.7)   # 替换横坐标x的值

# for a, b in zip(x1, D1):
#     plt.text(a, b + 0.01, '%.2f' % b, ha='center', va='bottom', fontsize=7)

# for a, b in zip(x2, D2):
#     plt.text(a, b + 0.01, '%.2f' % b, ha='center', va='bottom', fontsize=7)

# for a, b in zip(x3, D3):
#     plt.text(a, b + 0.01, '%.2f' % b, ha='center', va='bottom', fontsize=7)

# for a, b in zip(x4, D4):
#     plt.text(a, b + 0.01, '%.2f' % b, ha='center', va='bottom', fontsize=7)

# plt.legend(loc="upper center",ncol=4)   # 给出图例 
# bbox_to_anchor=(0.13,0.98),loc="best"
plt.legend(loc="best",prop = {'size':8})   # 给出图例
plt.savefig('Each_ACC.png', dpi=300, bbox_inches='tight')  # 保存图片
plt.show()

